using System;
using System.Runtime.InteropServices;

namespace Catastrophe.Common.WindowsApi
{
	public class PlayMusicUtil
	{
		public static uint SND_ASYNC = 1u;

		public static uint SND_FILENAME = 131072u;

		[DllImport("winmm.dll")]
		public static extern uint mciSendString(string lpstrCommand, string lpstrReturnString, uint uReturnLength, uint hWndCallback);

		public static void PlayNmusinc(string path)
		{
			PlayMusicUtil.mciSendString("close temp_alias", null, 0u, 0u);
			PlayMusicUtil.mciSendString("open \"" + path + "\" alias temp_alias", null, 0u, 0u);
			PlayMusicUtil.mciSendString("play temp_alias repeat", null, 0u, 0u);
		}

		public static void PlayMusic_Repeat(string p_FileName)
		{
			try
			{
				PlayMusicUtil.mciSendString("close temp_music", " ", 0u, 0u);
				PlayMusicUtil.mciSendString("open " + p_FileName + " alias temp_music", " ", 0u, 0u);
				PlayMusicUtil.mciSendString("play temp_music repeat", " ", 0u, 0u);
			}
			catch
			{
			}
		}

		public static void PlayMusic(string p_FileName)
		{
			try
			{
				PlayMusicUtil.mciSendString("close temp_music", " ", 0u, 0u);
				PlayMusicUtil.mciSendString("open \"" + p_FileName + "\" alias temp_music", null, 0u, 0u);
				PlayMusicUtil.mciSendString("play temp_music", " ", 0u, 0u);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		public static void StopMusic(string p_FileName)
		{
			try
			{
				PlayMusicUtil.mciSendString("close " + p_FileName, " ", 0u, 0u);
			}
			catch
			{
			}
		}

		public static void StopTempMusic()
		{
			try
			{
				PlayMusicUtil.mciSendString("close temp_music", " ", 0u, 0u);
			}
			catch
			{
			}
		}
	}
}
